#ifndef _BASE_H_
#define _BASE_H_

#include <string>
#include <map>
#include "ayoo/config.h"
#include "ayoo/mysqlwrap.h"

namespace AYOO{

class BaseRow
{
};

class BaseDBI
{
public:
	BaseDBI(const std::string sHost, uint32_t iPort, const std::string &sUser, const std::string &sPswd)
	: m_sHost(sHost), m_iPort(iPort), m_sUser(sUser), m_sPswd(sPswd)
	{
	}

	BaseDBI(const Config& conf, const std::string &sLblHost="DB_HOST", const std::string &sLblPort="DB_PORT"
				, const std::string &sLblUser="DB_USER", const std::string &sLblPswd="DB_PSWD" )
	{
		this->m_sHost = conf.GetStr(sLblHost);
		this->m_iPort = conf.GetInt(sLblPort);
		this->m_sUser = conf.GetStr(sLblUser);
		this->m_sPswd = conf.GetStr(sLblPswd);
	}


	virtual ~BaseDBI()
	{
		for(std::map<uint32_t, MySQLWrap*>::iterator itr=m_conn_map.begin(); itr!=m_conn_map.end(); itr++)
		{
			MySQLWrap* pmys = itr->second;
			pmys->Close();
			delete pmys;
		}
	}

protected:
	std::string m_sHost;
	uint32_t m_iPort;
	std::string m_sUser;
	std::string m_sPswd;
	std::map<uint32_t, MySQLWrap*> m_conn_map;
protected:
	MySQLWrap* GetMySQL();
};


}; /*namespace:AYOO*/

#endif /*_BASE_H_*/

